<?php
class response
{
    private $action = null;
    private $vars   = array();
    private $view   = null;
    private $app    = null;

    public function __construct($action = 'ok')
    {
        $this->action = $action;
    }

    public function render()
    {
        switch ($this->action) {
        case 'ok':
            $view = new view($this->app);
            $view->display($this->view,$this->vars);
            break;
        case 'notfound':
            header(" ",true,404);
            $view = new view('sbook');
            $view->display('error_404');
            break;
        case 'redirect':
            print("Response redirect");
        default:
            throw new Exception('sbook/response: unknown response action!');
        }
    }

    public function assign($name,$value)
    {
        $this->vars[$name] = $value;
    }

    public function view($template, $app = THISAPP)
    {
        $this->view = $template;
        $this->app  = $app;
    }

    public function __get($name)
    {
        return $this->$name;
    }
}
?>
